﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLSingTowerMall
{
    partial class UserDetail
    {
        private bool isValid =true;
        private string errorMessage = string.Empty;

        public bool IsValid
        {
            get { return isValid; }
        }

        public string ErrorMessage
        {
            get { return errorMessage; }
        }

        public void InitializeBeforeUpdate()
        {
            isValid = true;
        }

        /*
        partial void OnUserIdChanging(global::System.Guid value)
        {
            isValid = false;
            errorMessage += "User ID cannot be changed" + Environment.NewLine;
        }
        */

        partial void OnGenderChanging(global::System.String value)
        {
            if (value != "M" && value != "F")
            {
                isValid = false;
                errorMessage += "Invalid Gender value [" + value + "]" + Environment.NewLine;
            }
        }

        partial void OnContactNoChanging(global::System.String value)
        {
            if (value == string.Empty)
            {
                isValid = false;
                errorMessage += "Contact Number cannot be empty" + Environment.NewLine;
            }
        }

        partial void OnDateofBirthChanging(Nullable<global::System.DateTime> value)
        {
            try
            {
                if (((DateTime.Today - value.Value).TotalDays / 365.2425) < 5)
                {
                    isValid = false;
                    errorMessage += "You must be above 4 years old to register with our website" + Environment.NewLine;
                }
            }
            catch
            {
                isValid = false;
                errorMessage += "Invalid date of birth provided" + Environment.NewLine;
            }
        }

        partial void OnFullNameChanging(global::System.String value)
        {
            if (value == string.Empty)
            {
                isValid = false;
                errorMessage += "Full Name may not be blank" + Environment.NewLine;
            }
        }
    }
}
